<template>
  <view class="" @click="goPay(record)">
    <view class="item">
      <!-- <view class="title" v-if="record.typeEnum == 'REPAIR'">设备报修</view> -->
      <view class="title">{{ record.typeEnum == 'REPAIR' ? '设备报修' : record.typeEnum == 'MAINTAIN' ? '设备保养' : 'NULL' }}</view>
      <view class="content">{{ record.stateName }}</view>
    </view>
    <view class="item">
      <view class="content">{{ record.machineModelNumber }}</view>
      <view class="price">￥ {{ (record.serveAmount ? record.serveAmount : 0) + (record.partAmount ? record.partAmount : 0) }}</view>
    </view>
  </view>
</template>

<script>
export default {
  props: ['records'],

  data() {
    return {
      record: {}
    };
  },
  mounted() {
    // console.log('>>>>', this.records);
    this.record = this.records;
  },
  deactivated() {
    // 关闭定时器
    setTimeout(() => {
      uni.$off('order');
    }, 2000);
  },

  methods: {
    goPay(record) {
      if (record.stateName == '服务支付中') {
        uni.navigateTo({
          url: '/pages/payConfirm/payAttachment'
        });
        let data = JSON.stringify(record);
        //加定时器解决第一次页面传参接收不到的问题
        setTimeout(() => {
          uni.$emit('order', data);
        }, 100);
      } else if (record.stateName == '配件支付中') {
        uni.navigateTo({
          url: '/pages/payConfirm/payConfirm'
        });
        let data = JSON.stringify(record);
        //加定时器解决第一次页面传参接收不到的问题
        setTimeout(() => {
          uni.$emit('order', data);
        }, 100);
      } else {
        uni.navigateTo({
          url: '/pages/order-state/order-state'
        });
        let data = JSON.stringify(record);
        //加定时器解决第一次页面传参接收不到的问题
        setTimeout(() => {
          uni.$emit('order', data);
        }, 100);
      }
      // if (record.stateName == '配件支付中') {
      //   console.log(record, 'records');
      //   console.log(record.stateName, 'itemType');
      //   uni.navigateTo({
      //     url: '/pages/payConfirm/payConfirm'
      //   });
      //   let data = JSON.stringify(record);
      //   //加定时器解决第一次页面传参接收不到的问题
      //   setTimeout(() => {
      //     uni.$emit('order', data);
      //   }, 100);
      // }
      // if (record.stateName == '已完成') {
      //   console.log(record, 'records');
      //   uni.navigateTo({
      //     url: '/pages/order-state/order-state'
      //   });
      //   let data = JSON.stringify(record);
      //   //加定时器解决第一次页面传参接收不到的问题
      //   setTimeout(() => {
      //     uni.$emit('order', data);
      //   }, 100);
      // }
    }
  }
};
</script>

<style lang="scss">
.item {
  color: #fff;
  display: flex;
  justify-content: space-between;
  padding: 10px;

  .title {
    font-weight: bold;
  }

  .price {
    color: #ffb612;
  }
}
</style>
